package org.xxpay.manage.merchant.ctrl;


import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xxpay.core.common.constant.Constant;
import org.xxpay.core.common.domain.XxPayPageRes;
import org.xxpay.core.entity.MchAccount;
import org.xxpay.core.entity.MchInfoElectric;
import org.xxpay.manage.common.ctrl.BaseController;
import org.xxpay.manage.merchant.service.MchAccountService;
import org.xxpay.manage.merchant.service.MchInfoService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
@RequestMapping(Constant.MGR_CONTROLLER_ROOT_PATH + "/electric")
public class McheleCtricController extends BaseController {

    @Autowired
    private MchInfoService mchInfoService;

    @Autowired
    private MchAccountService mchAccountService;



    @RequestMapping("/list")
    @ResponseBody
    public ResponseEntity<?> list(HttpServletRequest request) {
        JSONObject param = getJsonParam(request);
        MchInfoElectric MchInfoElectric = getObject(param, MchInfoElectric.class);
        int count = mchInfoService.countAuditIsOk(MchInfoElectric);
        if(count == 0) return ResponseEntity.ok(XxPayPageRes.buildSuccess());
        List<MchAccount> mchInfoList = mchAccountService.getAllAccount((getPageIndex(param) - 1) * getPageSize(param), getPageSize(param));

        return ResponseEntity.ok(XxPayPageRes.buildSuccess(mchInfoList, count));
    }

}
